package com.softeem.work.myw8;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/21 14:16
 * @description
 */


public class LogDao {
    Scanner input = new Scanner(System.in);
    // * 1. 学生添加
    public void addstu(ArrayList<Student> students){
        System.out.println("请输入学生编号");
        String id = input.next();
        System.out.println("请输入学生姓名");
        String name = input.next();
        System.out.println("请输入学生密码");
        String password = input.next();
        students.add(new Student(id,name,password));
        System.out.println("学生添加完成");
    }
    // * 2. 学生登录
    public Student logon(ArrayList<Student> students){
        System.out.println("请输入学生姓名");
        String name = input.next();
        System.out.println("请输入学生密码");
        String password = input.next();
        for (Student student : students) {
            if (name.equals(student.getName())){
                if (password.equals(student.getPassword())){
                    System.out.println("登陆成功");
                    return student;
                }else {
                    System.out.println("密码错误");
                }
            }
        }
        System.out.println("查无此人");
        return null;
    }
    // * 3. 日志提交
    // * 4. 日志编号要求自动生成(可从1开始自动递增)
    public void up(ArrayList<Log> logs,Student student){
        System.out.println("请输入今日学习内容");
        String content = input.next();
        System.out.println("请输入掌握程度(了解，熟练，精通)");
        String zhangwo = input.next();
        System.out.println("请输入疑问");
        String question = input.next();
        //元素+学生类
        Log log = new Log(Log.getId(),content,zhangwo,question,student);
        Log.setId(Log.getId()+1);
        logs.add(log);
        System.out.println("日志提交完成");
    }
    // * 5. 查看当前登录人提交的所有日志
    public void findLogs(ArrayList<Log> logs,Student student){
        for (int i = 0; i < logs.size(); i++) {
            if (logs.get(i).getStudent().getName().equals(student.getName())){
                System.out.println(logs.get(i));
            }
        }
    }
    // * 6. 修改当前等路人提交的日志内容
    public void editLogs(ArrayList<Log> logs,Student student){
        for (int i = 0; i < logs.size(); i++) {
            if (logs.get(i).getStudent().getName().equals(student.getName())){
                System.out.println(logs.get(i));
                System.out.println("是否修改（y/n）");
                String next = input.next();
                if (next.equals("y")){
                    System.out.println("请输入要修改的学习内容");
                    String content = input.next();
                    System.out.println("请输入要修改的掌握程度(了解，熟练，精通)");
                    String zhangwo = input.next();
                    System.out.println("请输入要修改的疑问");
                    String question = input.next();
                    logs.get(i).setContent(content);
                    logs.get(i).setZhangwo(zhangwo);
                    logs.get(i).setQuestion(question);
                }
            }
        }
        System.out.println("修改结束");
    }
    // * 7. 退出登录
}
